unit AddRodstv;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dRoot, DB, StdCtrls, Buttons, ExtCtrls, ComCtrls, cxStyles,
  dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinCaramel, dxSkinCoffee,
  dxSkinDarkSide, dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinPumpkin,
  dxSkinSilver, dxSkinStardust, dxSkinSummer2008, dxSkinsDefaultPainters,
  dxSkinValentine, dxSkinXmas2008Blue, dxSkinscxPCPainter, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, Menus,
  cxLookAndFeelPainters, IBCustomDataSet, IBQuery, cxButtons, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxControls, cxGridCustomView, cxGrid;

type
  TfmAddRodstv = class(TdlgRoot)
    Label1: TLabel;
    Edit1: TEdit;
    dbgClients: TcxGrid;
    tvPeople: TcxGridDBTableView;
    tvPeoplePP: TcxGridDBColumn;
    tvPeoplePDATEBIRTH: TcxGridDBColumn;
    dbgClientsLevel1: TcxGridLevel;
    bAdd: TcxButton;
    cxButton2: TcxButton;
    cxGrid2: TcxGrid;
    cxGridDBTableView2: TcxGridDBTableView;
    cxGridLevel2: TcxGridLevel;
    qPeople: TIBQuery;
    qPeoplePID: TIntegerField;
    qPeoplePDATEBIRTH: TDateField;
    qPeoplePP: TIBStringField;
    dsTemp: TDataSource;
    cxGridDBTableView2PP: TcxGridDBColumn;
    qPeopleSDNAME: TIBStringField;
    tvPeopleSDNAME: TcxGridDBColumn;
    procedure bAddClick(Sender: TObject);
    procedure cxButton2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Edit1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    rid, pid:integer;
  end;

var
  fmAddRodstv: TfmAddRodstv;

implementation

{$R *.dfm}

procedure TfmAddRodstv.bAddClick(Sender: TObject);
begin
  inherited;
  if qPeople.IsEmpty then Exit;
  if dsTemp.DataSet.Locate('pid', dlgDS.DataSet.FieldValues['PID'], []) then Exit;

  dsTemp.DataSet.Insert;
  dsTemp.DataSet.FieldByName('RID').AsInteger := rid;
  dsTemp.DataSet.FieldByName('PID').AsInteger := dlgDS.DataSet.FieldByName('PID').AsInteger;
  dsTemp.DataSet.FieldByName('PP').AsString := dlgDS.DataSet.FieldByName('PP').AsString;
  dsTemp.DataSet.Post;
end;

procedure TfmAddRodstv.cxButton2Click(Sender: TObject);
begin
  inherited;
  if dsTemp.DataSet.IsEmpty then Exit;
  dsTemp.DataSet.Delete;
end;

procedure TfmAddRodstv.BitBtn1Click(Sender: TObject);
begin
  inherited;
  ModalResult := mrNone;
  if not CheckEditing then exit;
  ModalResult := mrOk;
end;

procedure TfmAddRodstv.FormShow(Sender: TObject);
begin
  inherited;
  qPeople.Open;
end;

procedure TfmAddRodstv.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  qPeople.Close;
end;

procedure TfmAddRodstv.FormCreate(Sender: TObject);
begin
  inherited;
  ;
end;

procedure TfmAddRodstv.Edit1Change(Sender: TObject);
begin
  inherited;
  
  tvPeople.DataController.Controller.IncSearchingText := edit1.Text;
  tvPeople.DataController.Controller.IsIncSearching;
end;

procedure TfmAddRodstv.Edit1Click(Sender: TObject);
begin
  inherited;
  ActivateKeyboardLayout(LoadKeyboardLayout('00000419', 0), 0);
end;

procedure TfmAddRodstv.BitBtn2Click(Sender: TObject);
begin
  inherited;
  dsTemp.DataSet.Cancel;
end;

end.
